package biz.inv.service;


import biz.inv.dto.Balance;
import glen.util.TemplateDAO;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;


public class BalanceSvr extends TemplateDAO<Balance, Integer> {

    public BalanceSvr() {
        super(Balance.class);

    }

    public BalanceSvr(Class<Balance> type) {
        super(type);

    }

    public BalanceSvr(Class<Balance> type, SqlSessionFactory sf) {
        super(type, sf);

    }

    public boolean save(Balance balance) {

        try (SqlSession session = sf.openSession()) {
            if (this.get(balance.getProductId()) == null) {
                session.insert("Balance.create", balance);
            } else {
                session.update("Balance.update", balance);
            }
            session.commit();
        }
        return true;
    }

}
